package com.tshopping.controller;

import com.tshopping.bean.Store;
import com.tshopping.service.StoreService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @name: StoreController
 * @description: TODO
 * @author: Jackeys
 * @date: 2021-01-22 16:04
 */
@RestController
@RequestMapping("/StoreController")
@CrossOrigin
public class StoreController {

    @Autowired
    private StoreService storeService;

    @PostMapping(value = "/uploadStorePicture")
    /**
     * @description 上传店铺封面
     * @Param: request
     * @Param: email
     * @Param: file
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-22 19:19
     */
    public ResponseData uploadStorePicture(HttpServletRequest request, String email, @RequestParam(value = "file", required = false) MultipartFile file) {
        return storeService.uploadStoreCoverFile(request, email, file);
    }

    @PostMapping(value = "/addStore")
    /**
     * @description 申请店铺
     * @Param: user
     * @Param: address
     * @Param: name
     * @Param: description
     * @Param: picture
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-22 20:01
     */
    public ResponseData addStore(int user, String address, String name, String description, String picture) {
        return storeService.addStore(user, address, name, description, picture);
    }

    @PostMapping(value = "/updateStore")
    /**
     * @description 修改店铺
     * @Param: address
     * @Param: name
     * @Param: description
     * @Param: picture
     * @Param: isApprove
     * @Param: user
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-22 20:44
     */
    public ResponseData updateStore(String address, String name, String description, String picture, int isApprove, int user, int id) {
        return storeService.updateStore(address, name, description, picture, isApprove, user, id);
    }

    @PostMapping(value = "/getStore")
    /**
     * @description 获取店铺
     * @Param: user
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-22 20:46
     */
    public ResponseData getStore(int user) {
        return storeService.selectStore(user);
    }

    @PostMapping(value = "/getStoreById")
    /**
     * @description 处理用户查询店铺
     * @Param: int
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 10:05
     */
    public ResponseData getStoreById(int id){
        return storeService.selectStoreById(id);
    }

    @PostMapping(value = "/getStoreData")
    /**
     * @description 返回店铺商品与信息
     * @Param: store
     * @Param: user
     * @Param: currentPage
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-29 21:55
     */
    public ResponseData getStoreData(int store,int user,int currentPage){
        return storeService.selectStoreInformation(store,user,currentPage);
    }
}
